home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / System / HDGarbageCollector / helpBox.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-03  |  6.6 KB  |  277 lines  |  [TEXT/KAHL]

  1. static pascal void HelpScrollProc(ControlHandle theControl,int theCode)
  2. {
  3. int            scrollAmt,height;
  4. int            controlMax,controlMin,controlVal;
  5. TEHandle    whichTEH;
  6.  
  7.     whichTEH = (TEHandle) GetCRefCon(theControl);
  8.     
  9.     controlMax = GetCtlMax(theControl);
  10.     controlMin = GetCtlMin(theControl);
  11.     controlVal = GetCtlValue(theControl);
  12.     
  13.     switch (theCode) 
  14.     {
  15.         case inUpButton:
  16.             if (controlVal > controlMin)
  17.             {
  18.                 SetCtlValue(theControl,controlVal-1);
  19.                 
  20.                 TEScroll(0,TEGetHeight(controlVal-1,controlVal-1,whichTEH),whichTEH);
  21.             }
  22.             
  23.             break;
  24.             
  25.         case inDownButton: 
  26.             if (controlVal < controlMax)
  27.             {
  28.                 SetCtlValue(theControl,controlVal+1);
  29.                 
  30.                 TEScroll(0,-TEGetHeight(controlVal,controlVal,whichTEH),whichTEH);
  31.             }
  32.             
  33.             break;
  34.  
  35.         case inPageUp: 
  36.             if (controlVal > controlMin)
  37.             {
  38.                 scrollAmt = 1;
  39.                 height = (**whichTEH).viewRect.bottom - (**whichTEH).viewRect.top;
  40.                 
  41.                 while (controlVal-scrollAmt>controlMin && TEGetHeight(controlVal-scrollAmt,controlVal-1,whichTEH)<height)
  42.                     scrollAmt++;
  43.                 
  44.                 if (scrollAmt>1  && TEGetHeight(controlVal-scrollAmt,controlVal-1,whichTEH)>height)
  45.                     scrollAmt--;
  46.                 
  47.                 SetCtlValue(theControl,controlVal-scrollAmt);
  48.                 
  49.                 TEScroll(0,TEGetHeight(controlVal-scrollAmt,controlVal-1,whichTEH),whichTEH);
  50.             }
  51.             
  52.             break;
  53.  
  54.         case inPageDown: 
  55.             if (controlVal < controlMax)
  56.             {
  57.                 scrollAmt = 1;
  58.                 height = (**whichTEH).viewRect.bottom - (**whichTEH).viewRect.top;
  59.                 
  60.                 while (controlVal+scrollAmt<controlMax && TEGetHeight(controlVal,controlVal+scrollAmt-1,whichTEH)<height)
  61.                     scrollAmt++;
  62.                 
  63.                 if (scrollAmt>1  && TEGetHeight(controlVal,controlVal+scrollAmt-1,whichTEH)>height)
  64.                     scrollAmt--;
  65.                 
  66.                 SetCtlValue(theControl,controlVal+scrollAmt);
  67.                 
  68.                 TEScroll(0,-TEGetHeight(controlVal,controlVal+scrollAmt-1,whichTEH),whichTEH);
  69.             }
  70.             
  71.             break;
  72.     }
  73. }
  74.  
  75.  
  76.  
  77. void DoHelpBox(int helpResWIND,int helpResTEXT,int helpResSTYL)
  78. {
  79. GrafPtr            oldPort,helpWPtr;
  80. TEHandle        helpTEH;
  81. Rect            destRect,viewRect,vScrollRect,doneRect;
  82. Handle            helpText,helpStyle;
  83. ControlHandle    vScrollControl,doneControl,whichControl;
  84. EventRecord        theEvent;
  85. int                cntlCode,controlVal,oldVal,height;
  86. char            theChar;
  87.  
  88.  
  89.     GetPort(&oldPort);
  90.     
  91.     helpWPtr = GetNewWindow(helpResWIND,0L,(WindowPtr) -1L);
  92.     SetPort(helpWPtr);
  93.     
  94.     CenterWindow(helpWPtr);
  95.     ShowWindow(helpWPtr);
  96.     
  97.     TextFont(geneva);
  98.     TextSize(10);
  99.     TextFace(0);
  100.     
  101.     SetRect(&viewRect,helpWPtr->portRect.left,helpWPtr->portRect.top,helpWPtr->portRect.right-15,helpWPtr->portRect.bottom-35);
  102.     InsetRect(&viewRect,5,5);
  103.     destRect = viewRect;
  104.     
  105.     
  106.     helpTEH = TEStylNew(&destRect,&viewRect);
  107.     
  108.     (**helpTEH).lineHeight = -1;
  109.     (**helpTEH).fontAscent = -1;
  110.     
  111.     InsetRect(&viewRect,-5,-5);
  112.     FrameRect(&viewRect);
  113.     
  114.     SetRect(&vScrollRect,viewRect.right-1,viewRect.top,helpWPtr->portRect.right,viewRect.bottom);
  115.     vScrollControl = NewControl(helpWPtr,&vScrollRect,"\p",TRUE,1,1,1,scrollBarProc,(long) helpTEH);
  116.     SetRect(&vScrollRect,viewRect.right-1,viewRect.top+16,helpWPtr->portRect.right,viewRect.bottom-16);
  117.     
  118.     SetRect(&doneRect,helpWPtr->portRect.right-55,helpWPtr->portRect.bottom-25,helpWPtr->portRect.right-5,helpWPtr->portRect.bottom-5);
  119.     doneControl = NewControl(helpWPtr,&doneRect,"\pDone",TRUE,0,0,1,pushButProc,0L);
  120.     
  121.     PenNormal();
  122.     PenSize(3,3);
  123.     InsetRect(&doneRect,-4,-4);
  124.     FrameRoundRect(&doneRect,16,16);
  125.     InsetRect(&doneRect,4,4);
  126.     PenSize(1,1);
  127.     
  128.     helpText = GetResource('TEXT',helpResTEXT);
  129.     helpStyle = GetResource('styl',helpResSTYL);
  130.     
  131.     if (helpText!=0L && helpStyle!=0L)
  132.     {
  133.         HLock(helpText);
  134.         
  135.         TEStylInsert(*helpText,SizeResource(helpText),helpStyle,helpTEH);
  136.         
  137.         HUnlock(helpText);
  138.         ReleaseResource(helpText);
  139.         ReleaseResource(helpStyle);
  140.         
  141.         
  142.         oldVal = (**helpTEH).nLines;
  143.         controlVal = 1;
  144.         height = (**helpTEH).viewRect.bottom - (**helpTEH).viewRect.top;
  145.         
  146.         while (oldVal-controlVal>1 && TEGetHeight(oldVal-controlVal,oldVal-1,helpTEH)<height)
  147.             controlVal++;
  148.         
  149.         if (controlVal>1  && TEGetHeight(oldVal-controlVal,oldVal-1,helpTEH)>height)
  150.             controlVal--;
  151.         
  152.         SetCtlMax(vScrollControl,oldVal-controlVal);
  153.         
  154.         BeginUpdate(helpWPtr);
  155.         EndUpdate(helpWPtr);
  156.         
  157.         do
  158.         {
  159.             SystemTask();
  160.             
  161.             cntlCode = 0;
  162.             
  163.             if (GetNextEvent(everyEvent,&theEvent))
  164.             {
  165.                 if (theEvent.what == mouseDown)
  166.                 {
  167.                     GlobalToLocal(&theEvent.where);
  168.                     
  169.                     cntlCode = FindControl(theEvent.where,helpWPtr,&whichControl);
  170.                     
  171.                     if (cntlCode != 0)
  172.                     {
  173.                         if (whichControl == vScrollControl)
  174.                         {
  175.                             if (cntlCode == inThumb)
  176.                             {
  177.                                 oldVal = GetCtlValue(vScrollControl);
  178.                                 
  179.                                 TrackControl(vScrollControl,theEvent.where,0L);
  180.                                 
  181.                                 controlVal = GetCtlValue(vScrollControl);
  182.                                 
  183.                                 if (controlVal > oldVal)
  184.                                     TEScroll(0,-TEGetHeight(oldVal,controlVal-1,helpTEH),helpTEH);
  185.                                     
  186.                                 else if (controlVal < oldVal)
  187.                                     TEScroll(0,TEGetHeight(controlVal,oldVal-1,helpTEH),helpTEH);
  188.                             }
  189.                             
  190.                             else
  191.                                 TrackControl(vScrollControl,theEvent.where,HelpScrollProc);
  192.                         }
  193.                         
  194.                         else if (whichControl == doneControl)
  195.                             cntlCode = TrackControl(doneControl,theEvent.where,0L);
  196.                         
  197.                         else
  198.                             SysBeep(1);
  199.                     }
  200.                     else
  201.                         SysBeep(1);
  202.                 }
  203.                 
  204.                 else if (theEvent.what==keyDown || theEvent.what==autoKey)
  205.                 {
  206.                     theChar = theEvent.message & charCodeMask;
  207.                     
  208.                     if (theChar == (char) 0x0d || theChar == (char) 0x03 || theChar == 'd' || theChar == 'D')
  209.                         cntlCode = inButton;
  210.                 }
  211.                 
  212.                 else if (theEvent.what==updateEvt && (WindowPtr) theEvent.message==helpWPtr)
  213.                 {
  214.                     BeginUpdate(helpWPtr);
  215.                     
  216.                     DrawControls(helpWPtr);
  217.                     
  218.                     if (FrontWindow() != helpWPtr)
  219.                         EraseRect(&vScrollRect);
  220.                     else
  221.                     {
  222.                         PenNormal();
  223.                         PenSize(3,3);
  224.                         InsetRect(&doneRect,-4,-4);
  225.                         FrameRoundRect(&doneRect,16,16);
  226.                         InsetRect(&doneRect,4,4);
  227.                         PenSize(1,1);
  228.                     }
  229.                     
  230.                     TEUpdate(&viewRect,helpTEH);
  231.                     FrameRect(&viewRect);
  232.                     
  233.                     EndUpdate(helpWPtr);
  234.                 }
  235.                 
  236.                 else if (theEvent.message==activateEvt && (WindowPtr) theEvent.message==helpWPtr) 
  237.                 {
  238.                     if (theEvent.modifiers & activeFlag) 
  239.                     {
  240.                         TEActivate(helpTEH);
  241.                         HiliteControl(doneControl,0);
  242.                         
  243.                         PenNormal();
  244.                         PenSize(3,3);
  245.                         InsetRect(&doneRect,-4,-4);
  246.                         FrameRoundRect(&doneRect,16,16);
  247.                         InsetRect(&doneRect,4,4);
  248.                     }
  249.                     else 
  250.                     {
  251.                         TEDeactivate(helpTEH);
  252.                         EraseRect(&vScrollRect);
  253.                         
  254.                         HiliteControl(doneControl,255);
  255.                         PenNormal();
  256.                         PenSize(3,3);
  257.                         PenPat(white);
  258.                         InsetRect(&doneRect,-4,-4);
  259.                         FrameRoundRect(&doneRect,16,16);
  260.                         InsetRect(&doneRect,4,4);
  261.                     }
  262.                 }
  263.             }
  264.         
  265.         } while (cntlCode != inButton);
  266.     }
  267.     else
  268.     {
  269.         SysBeep(1);
  270.         SysBeep(1);
  271.         SysBeep(1);
  272.     }
  273.     
  274.     
  275.     KillControls(helpWPtr);
  276.     DisposeWindow(helpWPtr);
  277. }